<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NFC答案之书</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
            overflow-x: hidden;
        }
        
        .container {
            max-width: 900px;
            width: 100%;
            text-align: center;
            animation: fadeIn 1s ease-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        header {
            margin-bottom: 30px;
        }
        
        h1 {
            font-size: 3rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
            background: linear-gradient(45deg, #ff9a9e, #fad0c4, #a1c4fd);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .subtitle {
            font-size: 1.3rem;
            margin-bottom: 10px;
            opacity: 0.9;
        }
        
        .description {
            max-width: 600px;
            margin: 0 auto 40px;
            line-height: 1.6;
            background: rgba(255, 255, 255, 0.1);
            padding: 15px;
            border-radius: 10px;
            font-size: 1.1rem;
        }
        
        .card-area {
            position: relative;
            width: 320px;
            height: 420px;
            margin: 0 auto 40px;
            perspective: 1000px;
        }
        
        .card {
            width: 100%;
            height: 100%;
            position: relative;
            transform-style: preserve-3d;
            transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            cursor: pointer;
        }
        
        .card.flipped {
            transform: rotateY(180deg);
        }
        
        .card-front, .card-back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            border-radius: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 30px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
            transition: all 0.3s ease;
        }
        
        .card-front {
            background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 100%);
            color: #333;
        }
        
        .card-front:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
        }
        
        .card-back {
            background: linear-gradient(45deg, #a1c4fd 0%, #c2e9fb 100%);
            color: #333;
            transform: rotateY(180deg);
            overflow-y: auto;
        }
        
        .nfc-icon {
            font-size: 100px;
            margin-bottom: 25px;
            color: #6a11cb;
        }
        
        .card-title {
            font-size: 2.2rem;
            margin-bottom: 15px;
            font-weight: 700;
        }
        
        .card-instruction {
            font-size: 1.2rem;
            line-height: 1.5;
            text-align: center;
        }
        
        .answer {
            font-size: 1.6rem;
            line-height: 1.6;
            font-style: italic;
            text-align: center;
            margin-bottom: 20px;
            font-weight: 500;
            min-height: 120px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .tap-area {
            background: rgba(255, 255, 255, 0.2);
            padding: 18px 35px;
            border-radius: 50px;
            font-size: 1.3rem;
            margin-top: 20px;
            cursor: pointer;
            transition: all 0.3s;
            display: inline-block;
            border: 2px solid rgba(255, 255, 255, 0.3);
            font-weight: 600;
            letter-spacing: 1px;
        }
        
        .tap-area:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.05);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        
        .tap-area:active {
            transform: scale(0.98);
        }
        
        .history {
            margin-top: 50px;
            width: 100%;
            max-width: 700px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            padding: 25px;
            backdrop-filter: blur(10px);
        }
        
        .history h2 {
            margin-bottom: 20px;
            font-size: 1.8rem;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .history-list {
            list-style-type: none;
            max-height: 250px;
            overflow-y: auto;
            padding: 10px;
        }
        
        .history-item {
            padding: 12px 15px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
            text-align: left;
            display: flex;
            justify-content: space-between;
            transition: background 0.2s;
        }
        
        .history-item:hover {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
        }
        
        .history-item:last-child {
            border-bottom: none;
        }
        
        .history-time {
            font-size: 0.9rem;
            opacity: 0.7;
            min-width: 80px;
            text-align: right;
        }
        
        .clear-history {
            background: rgba(255, 255, 255, 0.15);
            border: none;
            color: white;
            padding: 8px 15px;
            border-radius: 20px;
            cursor: pointer;
            margin-top: 15px;
            transition: all 0.3s;
            font-size: 0.9rem;
        }
        
        .clear-history:hover {
            background: rgba(255, 255, 255, 0.25);
        }
        
        .nfc-info {
            margin-top: 40px;
            background: rgba(0, 0, 0, 0.2);
            padding: 20px;
            border-radius: 15px;
            max-width: 700px;
        }
        
        .nfc-info h3 {
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .footer {
            margin-top: 40px;
            padding: 20px;
            text-align: center;
            font-size: 0.9rem;
            opacity: 0.7;
        }
        
        @media (max-width: 600px) {
            h1 {
                font-size: 2.2rem;
            }
            
            .card-area {
                width: 280px;
                height: 370px;
            }
            
            .answer {
                font-size: 1.4rem;
            }
            
            .history {
                padding: 15px;
            }
        }
        
        /* 滚动条样式 */
        ::-webkit-scrollbar {
            width: 8px;
        }
        
        ::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb {
            background: rgba(255, 255, 255, 0.3);
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb:hover {
            background: rgba(255, 255, 255, 0.5);
        }
        
        .pulse {
            animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        
        .floating {
            animation: floating 3s ease-in-out infinite;
        }
        
        @keyframes floating {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>NFC答案之书</h1>
            <p class="subtitle">刷一下卡片，获取人生指引</p>
            <div class="description">
                <p>这是一个模拟NFC功能的答案之书应用。点击卡片或按钮，随机获取一条人生建议或答案。</p>
                <p>在实际应用中，可以通过NFC标签触发答案显示。</p>
            </div>
        </header>
        
        <div class="card-area">
            <div class="card">
                <div class="card-front">
                    <div class="nfc-icon floating">
                        <i class="fas fa-book"></i>
                    </div>
                    <h2 class="card-title">答案之书</h2>
                    <p class="card-instruction">点击卡片或下方按钮获取你的专属答案</p>
                    <div class="tap-area pulse">
                        <i class="fas fa-hand-point-up"></i> 点击获取答案
                    </div>
                </div>
                <div class="card-back">
                    <p class="answer" id="answer-text">点击获取答案</p>
                    <div class="tap-area">
                        <i class="fas fa-redo"></i> 再次获取
                    </div>
                </div>
            </div>
        </div>
        
        <div class="history">
            <h2><i class="fas fa-history"></i> 历史答案</h2>
            <ul class="history-list" id="history-list">
                <!-- 历史记录将在这里显示 -->
            </ul>
            <button class="clear-history" id="clear-history">
                <i class="fas fa-trash"></i> 清除历史
            </button>
        </div>
        
        <div class="nfc-info">
            <h3><i class="fas fa-info-circle"></i> 关于NFC功能</h3>
            <p>在实际应用中，可以使用Web NFC API读取NFC标签内容。当手机靠近NFC标签时，会自动触发答案显示功能。</p>
            <p>目前Web NFC API仅支持Android设备上的Chrome浏览器。</p>
        </div>
        
        <div class="footer">
            <p>NFC答案之书 &copy; 2023 | 设计灵感来源于《答案之书》</p>
        </div>
    </div>

    <script>
        // 答案库
        const answers = [
            "是的，毫无疑问。",
            "不，现在不是时候。",
            "也许，再考虑一下。",
            "跟随你的直觉。",
            "结果可能会让你惊喜。",
            "需要更多信息。",
            "保持耐心，答案会自然显现。",
            "是的，但需要付出努力。",
            "不，风险太高。",
            "这是一个好机会。",
            "等待更好的时机。",
            "相信你的第一感觉。",
            "寻求他人的建议。",
            "答案在你心中。",
            "放手去做吧。",
            "再等等看。",
            "结果会如你所愿。",
            "需要做出改变。",
            "保持现状。",
            "跟随你的热情。",
            "答案是否定的。",
            "一切都会顺利。",
            "需要更多准备。",
            "是的，但要有耐心。",
            "不，寻找其他选择。",
            "跟随内心的声音。",
            "时机尚未成熟。",
            "大胆尝试。",
            "谨慎行事。",
            "答案就在眼前。",
            "相信过程。",
            "结果超出预期。",
            "需要更多勇气。",
            "顺其自然。",
            "答案即将揭晓。"
        ];
        
        // 获取DOM元素
        const card = document.querySelector('.card');
        const answerText = document.getElementById('answer-text');
        const tapButton = document.querySelector('.tap-area');
        const historyList = document.getElementById('history-list');
        const clearHistoryBtn = document.getElementById('clear-history');
        
        // 存储历史记录
        let history = JSON.parse(localStorage.getItem('answerHistory')) || [];
        
        // 初始化显示历史记录
        updateHistoryDisplay();
        
        // 获取随机答案
        function getRandomAnswer() {
            const randomIndex = Math.floor(Math.random() * answers.length);
            return answers[randomIndex];
        }
        
        // 显示答案
        function showAnswer() {
            // 翻转卡片
            card.classList.add('flipped');
            
            // 获取并显示随机答案
            const answer = getRandomAnswer();
            answerText.textContent = answer;
            
            // 添加到历史记录
            addToHistory(answer);
        }
        
        // 添加到历史记录
        function addToHistory(answer) {
            const timestamp = new Date().toLocaleTimeString();
            history.unshift({ answer, timestamp });
            
            // 更新历史记录显示
            updateHistoryDisplay();
            
            // 保存到本地存储
            localStorage.setItem('answerHistory', JSON.stringify(history));
            
            // 限制历史记录数量
            if (history.length > 10) {
                history.pop();
            }
        }
        
        // 更新历史记录显示
        function updateHistoryDisplay() {
            historyList.innerHTML = '';
            
            if (history.length === 0) {
                const emptyItem = document.createElement('li');
                emptyItem.className = 'history-item';
                emptyItem.textContent = '暂无历史记录';
                emptyItem.style.justifyContent = 'center';
                emptyItem.style.opacity = '0.7';
                historyList.appendChild(emptyItem);
                return;
            }
            
            history.forEach(item => {
                const li = document.createElement('li');
                li.className = 'history-item';
                
                const answerSpan = document.createElement('span');
                answerSpan.textContent = item.answer;
                
                const timeSpan = document.createElement('span');
                timeSpan.className = 'history-time';
                timeSpan.textContent = item.timestamp;
                
                li.appendChild(answerSpan);
                li.appendChild(timeSpan);
                historyList.appendChild(li);
            });
        }
        
        // 清除历史记录
        function clearHistory() {
            history = [];
            localStorage.removeItem('answerHistory');
            updateHistoryDisplay();
        }
        
        // 事件监听
        tapButton.addEventListener('click', showAnswer);
        card.addEventListener('click', showAnswer);
        clearHistoryBtn.addEventListener('click', clearHistory);
        
        // 初始显示一条历史记录（如果没有）
        if (history.length === 0) {
            addToHistory("欢迎使用NFC答案之书！");
        }
        
        // 添加键盘支持
        document.addEventListener('keydown', function(event) {
            if (event.code === 'Space' || event.code === 'Enter') {
                showAnswer();
            }
        });
    </script>
</body>
</html>